<template>
  <div class="doctor-detail-container">
    <!-- 顶部导航栏 -->
    <div class="header">
      <div class="header-content">
        <el-button @click="goBack" type="text" class="back-btn">
          <el-icon><ArrowLeft /></el-icon>
          返回
        </el-button>
        <h2>医生详情</h2>
        <div></div>
      </div>
    </div>

    <!-- 医生的信息 -->
    <div v-if="doctor" class="doctor-detail">
      <div class="doctor-header">
        <div class="doctor-avatar">
          <el-avatar :size="100" :src="doctor.avatar">
            {{ doctor.name.charAt(0) }}
          </el-avatar>
        </div>
        <div class="doctor-basic-info">
          <h1>{{ doctor.name }}</h1>
          <div class="doctor-title">{{ doctor.title }}</div>
          <div class="doctor-experience">行医经验：{{ doctor.experience }}</div>
        </div>
      </div>

      <!-- 专长介绍 -->
      <div class="info-section">
        <h3>专长介绍</h3>
        <div class="specialty-content">
          {{ doctor.specialty }}
        </div>
      </div>

      <!-- 出诊时间 -->
      <div class="info-section">
        <h3>出诊时间</h3>
        <div class="schedule-grid">
          <div 
            v-for="(schedule, index) in doctor.schedule" 
            :key="index"
            class="schedule-item"
            :class="{ available: schedule.available, unavailable: !schedule.available }"
          >
            <div class="schedule-day">{{ schedule.day }}</div>
            <div class="schedule-time">{{ schedule.time }}</div>
            <div class="schedule-status">
              {{ schedule.available ? '可预约' : '暂停' }}
            </div>
          </div>
        </div>
      </div>

      <!-- 预约按钮 -->
      <div class="appointment-section">
        <el-button 
          type="primary" 
          size="large" 
          class="appointment-btn"
          @click="goToAppointment"
        >
          立即预约
        </el-button>
      </div>
    </div>

    <!-- 加载状态 -->
    <div v-if="loading" class="loading">
      <el-skeleton :rows="5" animated />
    </div>

    <!-- 错误状态 -->
    <div v-if="!loading && !doctor" class="error-state">
      <el-empty description="医生信息不存在" />
    </div>
  </div>
</template>

<script>
import { ref, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
import { mockAPI } from '../utils/mockData'

export default {
  name: 'DoctorDetail',
  setup() {
    const router = useRouter()
    const route = useRoute()
    const doctor = ref(null)
    const loading = ref(false)

    const doctorId = route.params.doctorId

    // 获取医生详情
    const loadDoctorDetail = async () => {
      loading.value = true
      try {
        const result = await mockAPI.getDoctorDetail(doctorId)
        if (result.success) {
          doctor.value = result.data
        } else {
          ElMessage.error('获取医生信息失败')
        }
      } catch (error) {
        ElMessage.error('获取医生信息失败')
        console.error('获取医生详情失败:', error)
      } finally {
        loading.value = false
      }
    }

    // 跳转到预约页面
    const goToAppointment = () => {
      router.push(`/appointment/${doctorId}`)
    }

    // 返回上一页
    const goBack = () => {
      router.go(-1)
    }

    onMounted(() => {
      loadDoctorDetail()
    })

    return {
      doctor,
      loading,
      goToAppointment,
      goBack
    }
  }
}
</script>

<style scoped>
.doctor-detail-container {
  min-height: 100vh;
  background-color: #f5f5f5;
}

.header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 15px 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.back-btn {
  color: white;
  font-size: 16px;
  display: flex;
  align-items: center;
}

.back-btn .el-icon {
  margin-right: 5px;
}

.header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: bold;
}

.doctor-detail {
  max-width: 800px;
  margin: 20px auto;
  padding: 0 20px;
}

.doctor-header {
  background: white;
  border-radius: 15px;
  padding: 30px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.doctor-avatar {
  margin-right: 30px;
}

.doctor-basic-info h1 {
  margin: 0 0 10px 0;
  font-size: 28px;
  color: #333;
  font-weight: bold;
}

.doctor-title {
  font-size: 16px;
  color: #409EFF;
  margin-bottom: 8px;
  font-weight: 500;
}

.doctor-experience {
  font-size: 14px;
  color: #666;
}

.info-section {
  background: white;
  border-radius: 15px;
  padding: 25px;
  margin-bottom: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.info-section h3 {
  margin: 0 0 15px 0;
  font-size: 18px;
  color: #333;
  font-weight: 600;
}

.specialty-content {
  color: #666;
  line-height: 1.6;
  font-size: 14px;
}

.schedule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 15px;
}

.schedule-item {
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  padding: 15px;
  text-align: center;
  transition: all 0.3s ease;
}

.schedule-item.available {
  border-color: #4CAF50;
  background-color: #f8fff8;
}

.schedule-item.unavailable {
  border-color: #f44336;
  background-color: #fff8f8;
  opacity: 0.6;
}

.schedule-day {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin-bottom: 5px;
}

.schedule-time {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}

.schedule-status {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 12px;
  font-weight: 500;
}

.schedule-item.available .schedule-status {
  background-color: #4CAF50;
  color: white;
}

.schedule-item.unavailable .schedule-status {
  background-color: #f44336;
  color: white;
}

.appointment-section {
  background: white;
  border-radius: 15px;
  padding: 25px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.appointment-btn {
  width: 200px;
  height: 50px;
  font-size: 18px;
  border-radius: 25px;
}

.loading {
  max-width: 800px;
  margin: 20px auto;
  padding: 0 20px;
}

.error-state {
  max-width: 800px;
  margin: 40px auto;
  padding: 0 20px;
  text-align: center;
}

@media (max-width: 768px) {
  .doctor-header {
    flex-direction: column;
    text-align: center;
    padding: 20px;
  }
  
  .doctor-avatar {
    margin-right: 0;
    margin-bottom: 20px;
  }
  
  .doctor-basic-info h1 {
    font-size: 24px;
  }
  
  .schedule-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  
  .schedule-item {
    padding: 10px;
  }
  
  .appointment-btn {
    width: 100%;
  }
}
</style> 